﻿using B.Z.BasicData.API.Write.Application.Menu;
using B.Z.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.Z.BasicData.API.Write.Controllers
{
    /// <summary>
    /// 控制器-写（菜单）
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddMeun(MenuAddCommand command) 
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateMenu(MenuUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> RemoveMenu(MenuRemoveCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 为角色分配菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> RoleMenuAdd(RoleMenuAddCommand command)
        {
            return await mediator.Send(command);
        }
    }
}
